package com.sumer.psychology.friend.infrastructure.persistence;

import com.sumer.psychology.common.persistence.hibernate.AbstractHibernateRepository;
import com.sumer.psychology.friend.domain.model.Member;
import com.sumer.psychology.friend.domain.model.MemberId;
import com.sumer.psychology.friend.domain.model.MemberRepository;
import org.hibernate.Query;

/**
 * 社交成员资源库
 * <p/>
 * Created by zhu on 14-8-28.
 */
public class HibernateMemberRepository extends AbstractHibernateRepository implements MemberRepository {
    @Override
    public Member memberOfId(MemberId memberId) {
        Query query = session().
                createQuery("from com.sumer.psychology.friend.domain.model.Member m where m.memberId=:memberId").
                setParameter("memberId", memberId);
        return (Member) query.uniqueResult();
    }

    @Override
    public void add(Member aMember) {
        session().saveOrUpdate(aMember);
    }
}
